<?php


namespace TbfDatabase\MysqlAST\Test;


use TbfDatabase\MysqlAST\SelectCommand;
use TbfDatabase\MysqlAST\Sql;

class MysqlASTTest extends \PHPUnit_Framework_TestCase{
    public function test1(){
        $select = SelectCommand::create()->from('Table1')->where('a=1 AND b=?',array('c'))->limit('1,2');
        $this->assertSame($select->GetPrepareSql(),'SELECT * FROM Table1 WHERE a=1 AND b=? LIMIT 1,2');
        $this->assertSame($select->GetPrepareParameter(),array('c'));

        $copyed = $select->Copy();
        $copyed->limit('2,2');
        $this->assertSame($select->GetPrepareSql(),'SELECT * FROM Table1 WHERE a=1 AND b=? LIMIT 1,2');
        $this->assertSame($copyed->GetPrepareSql(),'SELECT * FROM Table1 WHERE a=1 AND b=? LIMIT 2,2');
    }

    public function testSelect(){
        $and = Sql::AndWhereCondition();
        $and->AddPrepare('a=1');
        $and->AddPrepare('d=?',array('c'));
        $select = SelectCommand::create()->from('Table1')->whereObj($and);
        $this->assertSame($select->GetPrepareSql(),'SELECT * FROM Table1 WHERE a=1 AND d=?');
        $this->assertSame($select->GetPrepareParameter(),array('c'));
    }
} 